import os
from pypdf import PdfMerger as pm

# 文件路径
pdf_path = r'E:\文档\PDF文件\\'
# 获取文件夹下pdf文件
pdf_lst = [f for f in os.listdir(pdf_path) if f.endswith('.pdf')]
# 合成绝对路径
pdf_lst = [os.path.join(pdf_path, filename) for filename in pdf_lst]

# 合并pdf
pdf_merger = pm()
for pdf in pdf_lst:
    pdf_merger.append(pdf, outline_item=False)

# 合并文件保存
pdf_merger.write(pdf_path + r'合并文件.pdf')
print('合并完成！')